package com.androidx.p013lv.mine.activity;

import android.net.Uri;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.androidx.p013lv.base.bean.OnLineServiceBean;
import com.androidx.p013lv.base.http.BaseRes;
import com.androidx.p013lv.base.http.HttpUtils;
import com.androidx.p013lv.base.http.UrlManager;
import com.androidx.p013lv.base.http.callback.HttpCallback;
import com.androidx.p013lv.base.p015ui.BaseActivity;
import com.androidx.p013lv.base.utils.GlideEngine;
import com.androidx.p013lv.base.utils.NetUtil;
import com.androidx.p013lv.base.utils.ToastUtils;
import com.androidx.p013lv.mine.C1207R;
import com.androidx.p013lv.mine.databinding.ActivityOnlineserviceBinding;
import com.gyf.immersionbar.ImmersionBar;
import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.config.PictureMimeType;
import com.luck.picture.lib.entity.LocalMedia;
import com.luck.picture.lib.listener.OnResultCallbackListener;
import java.io.File;
import java.util.List;
import p000a.p002b.RxPermissions;
import p023io.reactivex.disposables.Disposable;
import p023io.reactivex.functions.Consumer;

/* renamed from: com.androidx.lv.mine.activity.OnlineServiceActivity */
public class OnlineServiceActivity extends BaseActivity<ActivityOnlineserviceBinding> {
    public static String[] PERMISSIONS_CAMERA = {"android.permission.CAMERA", "android.permission.READ_EXTERNAL_STORAGE"};
    Disposable disposable;
    private ValueCallback<Uri[]> valueCallback;

    @Override // com.androidx.p013lv.base.p015ui.BaseActivity
    public int setLayout() {
        return C1207R.C1212layout.activity_onlineservice;
    }

    /* access modifiers changed from: protected */
    @Override // com.androidx.p013lv.base.p015ui.BaseActivity
    public void initImmersionBar() {
        super.initImmersionBar();
        ImmersionBar.with(this).titleBar(((ActivityOnlineserviceBinding) this.binding).toolbar).init();
    }

    /* access modifiers changed from: protected */
    @Override // com.androidx.p013lv.base.p015ui.BaseActivity
    public void initView() {
        super.initView();
        ((ActivityOnlineserviceBinding) this.binding).imgBack.setOnClickListener(new View.OnClickListener() {
            /* class com.androidx.p013lv.mine.activity.OnlineServiceActivity.View$OnClickListenerC12551 */

            public void onClick(View view) {
                OnlineServiceActivity.this.finish();
            }
        });
        ((ActivityOnlineserviceBinding) this.binding).statuLayout.setOnRetryListener(new View.OnClickListener() {
            /* class com.androidx.p013lv.mine.activity.OnlineServiceActivity.View$OnClickListenerC12562 */

            public void onClick(View view) {
                OnlineServiceActivity.this.doLogic();
            }
        });
        doLogic();
    }

    /* access modifiers changed from: package-private */
    public void doLogic() {
        if (!NetUtil.isNetworkAvailable()) {
            ((ActivityOnlineserviceBinding) this.binding).statuLayout.showNoNet();
            return;
        }
        HttpUtils.getInsatance().get(UrlManager.getInsatance().OnlineService(), new HttpCallback<BaseRes<OnLineServiceBean>>("OnLineServiceBean", getActivity()) {
            /* class com.androidx.p013lv.mine.activity.OnlineServiceActivity.C12573 */

            public void onLvSuccess(BaseRes<OnLineServiceBean> baseRes) {
                if (baseRes.getCode() == 200) {
                    OnlineServiceActivity.this.openUrl(baseRes.getData().getSignUrl());
                    return;
                }
                ((ActivityOnlineserviceBinding) OnlineServiceActivity.this.binding).statuLayout.showError();
                ToastUtils.getInstance().showWeak(baseRes.getMsg());
            }
        });
    }

    public void openUrl(String str) {
        ((ActivityOnlineserviceBinding) this.binding).f328wv.loadUrl(UrlManager.getInsatance().getBaseUrl() + str);
        ((ActivityOnlineserviceBinding) this.binding).f328wv.addJavascriptInterface(this, "android");
        ((ActivityOnlineserviceBinding) this.binding).f328wv.setWebChromeClient(new WebChromeClient() {
            /* class com.androidx.p013lv.mine.activity.OnlineServiceActivity.C12584 */

            public void onProgressChanged(WebView webView, int i) {
                super.onProgressChanged(webView, i);
                if (i == 100) {
                    ((ActivityOnlineserviceBinding) OnlineServiceActivity.this.binding).f327pb.setVisibility(8);
                } else {
                    ((ActivityOnlineserviceBinding) OnlineServiceActivity.this.binding).f327pb.setProgress(i);
                }
            }

            @Override // android.webkit.WebChromeClient
            public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> valueCallback, WebChromeClient.FileChooserParams fileChooserParams) {
                OnlineServiceActivity.this.valueCallback = valueCallback;
                OnlineServiceActivity.this.requestPermission();
                return true;
            }
        });
        ((ActivityOnlineserviceBinding) this.binding).f328wv.setWebViewClient(new WebViewClient());
        WebSettings settings = ((ActivityOnlineserviceBinding) this.binding).f328wv.getSettings();
        settings.setJavaScriptEnabled(true);
        settings.setCacheMode(1);
    }

    @Override // androidx.appcompat.app.AppCompatActivity
    public boolean onKeyDown(int i, KeyEvent keyEvent) {
        if (!((ActivityOnlineserviceBinding) this.binding).f328wv.canGoBack() || i != 4) {
            return super.onKeyDown(i, keyEvent);
        }
        ((ActivityOnlineserviceBinding) this.binding).f328wv.goBack();
        return true;
    }

    public void requestPermission() {
        this.disposable = new RxPermissions(this).request(PERMISSIONS_CAMERA).subscribe(new Consumer<Boolean>() {
            /* class com.androidx.p013lv.mine.activity.OnlineServiceActivity.C12595 */

            public void accept(Boolean bool) throws Exception {
                if (bool.booleanValue()) {
                    OnlineServiceActivity.this.selePic();
                }
            }
        });
    }

    public void selePic() {
        PictureSelector.create(this).openGallery(PictureMimeType.ofImage()).loadImageEngine(GlideEngine.createGlideEngine()).maxSelectNum(1).compress(true).forResult(new OnResultCallbackListener<LocalMedia>() {
            /* class com.androidx.p013lv.mine.activity.OnlineServiceActivity.C12606 */

            @Override // com.luck.picture.lib.listener.OnResultCallbackListener
            public void onResult(List<LocalMedia> list) {
                for (LocalMedia localMedia : list) {
                    if (OnlineServiceActivity.this.valueCallback != null) {
                        Uri fromFile = Uri.fromFile(new File(localMedia.getCompressPath()));
                        OnlineServiceActivity.this.valueCallback.onReceiveValue(new Uri[]{fromFile});
                    }
                }
            }

            @Override // com.luck.picture.lib.listener.OnResultCallbackListener
            public void onCancel() {
                if (OnlineServiceActivity.this.valueCallback != null) {
                    OnlineServiceActivity.this.valueCallback.onReceiveValue(null);
                }
            }
        });
    }
}
